<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
			<h1>GET</h1>
			<button type="button" onclick="Get1();">获取当前日期和时间</button>
			<br>
			<button type="button" onclick="Get2();">随机一句名言(GET/POST)</button>
			<br>
			<button type="button" onclick="Get3();">获取诗词列表-包含作者信息(GET/POST)</button>
			<br>
			<button type="button" onclick="Get4();">获取诗词作者列表(GET/POST)</button>
			<br>
			<button type="button" onclick="Get5();">平台接口预览</button>
			<br>
		<div id="thisdiv"></div>
	</body>
	<script type="text/javascript">
	// 获取当前日期和时间
		function Get1(){
			var ajax = new XMLHttpRequest();
			ajax.open('GET','http://poetry.apiopen.top/getTime');
			ajax.send();
			ajax.onreadystatechange = function(){
				if (ajax.status == 200 && ajax.readyState == 4) {
					var obj = JSON.parse(ajax.responseText);
					var thisdiv=document.getElementById('thisdiv');
					thisdiv.innerHTML=obj.result.dateTime;
					console.log(obj.result);
				}
			}
		}
		// 随机一句名言(GET/POST)
		function Get2(){
			var aa2=new XMLHttpRequest();
			aa2.open('GET','http://poetry.apiopen.top/sentences');
			aa2.send();
			aa2.onreadystatechange=function(){
				if (aa2.status==200&&aa2.readyState==4) {
					var abj2=JSON.parse(aa2.responseText);
					var thisdiv=document.getElementById('thisdiv');
					console.log(abj2.result);
					thisdiv.innerHTML=abj2.result.name+'——'+abj2.result.from;
				}
			}
		}
		// 获取诗词列表-包含作者信息(GET/POST)
		function Get3(){
			var aa3=new XMLHttpRequest();
			aa3.open('GET','http://poetry.apiopen.top/poetryFull?count=2&page=1');
			aa3.send();
			aa3.onreadystatechange=function(){
				if (aa3.status==200&&aa3.readyState==4) {
					var obj3=JSON.parse(aa3.responseText);
					var thisdiv=document.getElementById('thisdiv');
					console.log(obj3.result);
					thisdiv.innerHTML=(obj3.result)[0].content+'<br><br>'+(obj3.result)[0].simpleIntro
					+'<br><br>'+(obj3.result)[1].content+'<br><br>'+(obj3.result)[1].simpleIntro;
				}
			}
		}
		// 获取诗词作者列表(GET/POST)
		function Get4(){
			var aa4=new XMLHttpRequest();
			aa4.open('GET','http://poetry.apiopen.top/poetryAuthor?count=2&page=1&name=李白');
			aa4.send();
			aa4.onreadystatechange=function(){
				if (aa4.status==200&aa4.readyState==4) {
					var obj4=JSON.parse(aa4.responseText);
					var thisdiv=document.getElementById('thisdiv');
					
					console.log(obj4.result);
					
					thisdiv.innerHTML=obj4.result.name+','+obj4.result.simpleIntro;
				}
			}
		}
		// 平台接口预览
		function Get5(){
			var aa5=new XMLHttpRequest();
			aa5.open('GET','https://api.apiopen.top/getAllUrl');
			aa5.send();
			aa5.onreadystatechange=function(){
				if (aa5.status==200&aa5.readyState==4) {
					var obj5=JSON.parse(aa5.responseText);
					var sum=0;
					console.log(obj5);
					for (var i = 0; i < obj5.length; i++) {
						sum+=obj5[i]+'<br>';
					}
					thisdiv.innerHTML=sum;
				}
			}
		}
	</script>
</html>
